<?php
  if(isset($_GET['uid']) && is_numeric($_GET['uid']) && $_GET['uid'] > 0){
    $uid =  $_GET['uid'];
  }
  else{
    $uid = Session::factory()->getUserId();
  }
  
  if($_GET['op'] != 'xml'){
  	
    $smarty->assign("title", "Your Playlist");
    $_GET['uid'] = $uid;
    
    include_once "views/track/listen/index.php";
    exit();
  }
  
  include_once "lib/WebServices/Proxy.php";
  include_once "controllers/UserFavs.php";
  
  $pl = new UserFavs(array(user_id=>$uid));
  $pl->get();
  
  //print_r($pl->result());
  $xspf = '<?xml version="1.0" encoding="utf-8"?><playlist version="1" xmlns="http://xspf.org/ns/0/"><trackList>';
  
  foreach($pl->result() as $track){
  	$xspf .= "\n<track>\n<identifier>{$track->id}</identifier>\n".
              "<title>".htmlspecialchars("{$track->title} - {$track->artist} - {$track->release_title}", ENT_NOQUOTES)."</title>\n".
              "<location>{$track->url}</location>\n</track>\n";
  }
  
  $xspf .= '</trackList></playlist>';
  
  Proxy::send($xspf);
  
?>